package com.sl.service;


import com.sl.mapper.PaperMapper;
import com.sl.pojo.Paper;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PaperService {

    @Resource
    private PaperMapper paperMapper;
    //显示所有试题
    public List<Paper> all(){
        return  paperMapper.selectAll();
    }
    //ID主键  。找
    public Paper findById(Integer id){
        return  paperMapper.selectByPrimaryKey(id);
    }
    //新增
    public void add(Paper paper){
         paperMapper.insertSelective(paper);
    }
    //更新
    public void update(Paper paper){
        paperMapper.updateByPrimaryKeySelective(paper);
    }

    public Paper findByPaperName(String name){
        Example example = new Example(Paper.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("paper", name);
        Paper paper = paperMapper.selectOneByExample(example);
        return paper;
    }

    public  void deleted(Paper paper){
        paperMapper.deleteByPrimaryKey(paper);
    }

}
